﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace System.Collections
{
	public static class IEnumerableExtension
	{
		public static bool Any(this IEnumerable @this, Func<object, bool> condition)
		{
			foreach (var obj in @this)
			{
				if (condition(obj))
					return true;
			}

			return false;
		}

		public static object FirstOrDefault(this IEnumerable @this, Func<object, bool> condition)
		{
			foreach (var obj in @this)
			{
				if (condition(obj))
					return obj;
			}

			return null;
		}

		public static T[] Append<T>(this T[] array, params T[] newObj)
		{
			int len = array.Length;
			T[] newArray = new T[len + newObj.Length];
			Array.Copy(array, newArray, len);

			for (int i = 0; i < newObj.Length; i++)
				newArray[len + i] = newObj[i];

			return newArray;
		}

		public static void ForEach<T>(this IEnumerable<T> @this, Action<T> bodyAction)
		{
			foreach (var item in @this)
				bodyAction(item);
		}
	}
}
